function data = reformat ( house, sens )
% data = reformat ( house, sens )
% returns matrix with data of sensor 'sens'
% if 'sens' is set to 0, all sensory data is processed
%   column 1 start
%   column 2 log(duration)
%   column 3 numberof
%   column 4 weekend
%   column 5 sensorid
        
    sensorid=house.ss(:,3);
    
  % DURATION 
    duration=house.ss(:,2)-house.ss(:,1);

  % WEEKEND
    weekend=weekday(house.ss(:,1)); weekend=(weekend==1 | weekend==7);
    weekend=weekend+1;
    
    start=datevec(house.ss(:,1));
    y=start(:,1); m=start(:,2); d=start(:,3);
    
  % START  
    start=60*60*start(:,4)+60*start(:,5)+start(:,6);
  
  % NUMBEROF
    numberof=[];
    for i=1:length(sensorid)
        numb=0;
        total=0;
        for k=1:length(sensorid)
            if y(i)==y(k) & m(i)==m(k) & d(i)==d(k)
                if sensorid(i)==sensorid(k)
                    numb=numb+1; 
                else
                    total=total+1;
                end
            end
        end
        numberof(i)=numb/(numb+total);  % normalize
    end
    numberof=numberof';
    
  % DATA
    if sens~=0
        sensorfilter=(sensorid==sens);
        start=start.*sensorfilter;          start([start==0])=[];
        duration=duration.*sensorfilter;    duration([duration==0])=[];
        numberof=numberof.*sensorfilter;    numberof([numberof==0])=[];
        weekend=weekend.*sensorfilter;      weekend([weekend==0])=[];
        sensorid=sensorid.*sensorfilter;    sensorid([sensorid==0])=[];
    end
    
    data=[start/1000,log(duration),numberof,weekend,sensorid];

    
%     DURATION TO SECONDS (ALREADY PROPORTIONAL NOT NECESSARY)
%     duration=datevec(house.ss(:,2))-datevec(house.ss(:,1));
%     duration(:,2)=duration(:,2)*30*24*60*60;  % notice: february has less days
%     duration(:,3)=duration(:,3)*24*60*60;
%     duration(:,4)=duration(:,4)*60*60;
%     duration(:,5)=duration(:,5)*60;
%     duration=duration(:,2)+duration(:,3)+duration(:,4)+duration(:,5)+duration(:,6);


end

